<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>{$setting.webname}-视频管理</title>
  <meta name="keywords" content="">
  <meta name="description" content="">
  <link href="/public/static/admin/layui/css/layui.css" rel="stylesheet">
  <link rel="shortcut icon" href="/public/static/favicon.ico">
  <link href="/public/static/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
  <link href="/public/static/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
  <link href="/public/static/admin/css/plugins/iCheck/custom.css" rel="stylesheet">
  <link href="/public/static/admin/css/animate.css" rel="stylesheet">
  <link href="/public/static/admin/css/style.css?v=4.1.0" rel="stylesheet">
  <link href="/public/static/admin/css/plugins/switchery/switchery_smail.css" rel="stylesheet">
  <style>
    .update:hover,.del:hover{
       color:#23b7e5;
    }
  </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content">
  <div class="row">
    <div class="col-sm-3">
      <div class="ibox float-e-margins">
        <div class="ibox-content">
          <div class="file-manager">
            <div class="hr-line-dashed"></div>
            <button class="btn btn-primary btn-block function-btn" data-method="addvideo" data-type="addvideo" data-text="添加视频">添加视频</button>
            <div class="hr-line-dashed"></div>
            <h5>视频类型</h5>
            <ul class="folder-list" style="padding: 0">
              {foreach $videotype as $val}
              <li><a data-id="{$val.id}" class="search" id="search{$val.id}"><i class="fa fa-video-camera"></i> {$val.name}</a></li>
              {/foreach}
            </ul>

            <div class="clearfix"></div>
          </div>
        </div>
      </div>
    </div>
    <div class="col-sm-9 animated fadeInRight">
      <div class="row">
        <div class="col-sm-12" id="filebox">

        </div>
      </div>
    </div>
  </div>
</div>
<!--  添加视频开始  -->
<style>
  #file-upload-box{
    display: none;
    padding-bottom:0px;
  }
  #file-upload-box .form-group div{
    padding:0px;
  }
</style>
<div id="file-upload-box" class="ibox-content">
  <form class="form-horizontal" id="fileUploadForm">
    <!--视频标题-->
    <div class="form-group">
      <label class="col-sm-3 control-label">视频标题：</label>
      <div class="col-sm-8">
        <input type="text" name="title" placeholder="视频标题" class="form-control" id="title" autofocus="true">
        <span class="help-block m-b-none"></span>
      </div>
    </div>
    <!--视频关键词-->
    <div class="form-group">
      <label class="col-sm-3 control-label">关键词：</label>
      <div class="col-sm-8">
        <input type="text" name="keywords" placeholder="关键词" class="form-control" id="keywords" autofocus="true">
        <span class="help-block m-b-none">多个关键词之间使用逗号“,”隔开</span>
      </div>
    </div>
    <!--视频描述-->
    <div class="form-group">
      <label class="col-sm-3 control-label">视频描述：</label>
      <div class="col-sm-8">
        <input type="text" name="description" placeholder="视频描述" class="form-control" id="description" autofocus="true">
        <span class="help-block m-b-none"></span>
      </div>
    </div>
    <!--视频分类-->
    <div class="form-group">
      <label class="col-sm-3 control-label">视频分类：</label>
      <div class="col-sm-8">
        <select name="videotype" id="videotype" class="form-control">
          <option value="">请选择所属类型</option>
          {foreach $videotype as $val}
          <option value="{$val.id}">{$val.name}</option>
          {/foreach}
        </select>
        <span class="help-block m-b-none"></span>
      </div>
    </div>
    <!--视频封面-->
    <div class="form-group">
      <label class="col-sm-3 control-label">视频封面：</label>
      <div class="col-sm-8">
        <input type="button" class="btn btn-success" value="已上传的图片" id="selffile">
        <button type="button" class="btn btn-info" id="test1">上传图片</button>
        <div class="layui-upload-list">
          <img class="layui-upload-img" id="demo1" style='max-width:100%'>
          <p id="demoText"></p>
        </div>
      </div>
    </div>

    <!--上传视频-->
    <div class="form-group">
      <label class="col-sm-3 control-label">视频：</label>
      <div class="col-sm-8">
        <input type="button" class="btn btn-success" value="已上传的视频" id="self_video_file">
        <button type="button" class="btn btn-info" id="video_test1">上传视频</button>
        <div class="layui-upload-list">
          <video class="layui-upload-img" id="video_demo1" style='max-width:100%' controls></video>
          <p id="video_demoText"></p>
        </div>
      </div>
    </div>
    <!--排序-->
    <div class="form-group">
      <label class="col-sm-3 control-label">视频排序：</label>
      <div class="col-sm-8">
        <input type="number" name="sort" placeholder="视频排序" class="form-control" id="sort" autofocus="true">
        <span class="help-block m-b-none"></span>
      </div>
    </div>
    <!--状态-->
    <div class="form-group">
      <label class="col-sm-3 control-label">视频状态：</label>
      <div class="col-sm-8">
        <select name="status" id="status" class="form-control">
          <option value="1">显示</option>
          <option value="2">隐藏</option>
        </select>
        <span class="help-block m-b-none"></span>
      </div>
    </div>
  </form>
</div>

<!--  修改视频开始  -->
<style>
  #update-file-upload-box,#video_qrcode{
    display: none;
    padding-bottom:0px;
  }
  #update-file-upload-box .form-group div{
    padding:0px;
  }
</style>
<div id="update-file-upload-box" class="ibox-content">
  <form class="form-horizontal" id="updateFileUploadForm">
    <!--视频标题-->
    <div class="form-group">
      <label class="col-sm-3 control-label">视频标题：</label>
      <div class="col-sm-8">
        <input type="text" name="title" placeholder="视频标题" class="form-control" id="update_title" autofocus="true">
        <input type="hidden" name="id" class="form-control" id="update_id" autofocus="true">
        <span class="help-block m-b-none"></span>
      </div>
    </div>
    <!--视频关键词-->
    <div class="form-group">
      <label class="col-sm-3 control-label">关键词：</label>
      <div class="col-sm-8">
        <input type="text" name="keywords" placeholder="关键词" class="form-control" id="update_keywords" autofocus="true">
        <span class="help-block m-b-none">多个关键词之间使用逗号“,”隔开</span>
      </div>
    </div>
    <!--视频描述-->
    <div class="form-group">
      <label class="col-sm-3 control-label">视频描述：</label>
      <div class="col-sm-8">
        <input type="text" name="description" placeholder="视频描述" class="form-control" id="update_description" autofocus="true">
        <span class="help-block m-b-none"></span>
      </div>
    </div>
    <!--视频分类-->
    <div class="form-group">
      <label class="col-sm-3 control-label">视频分类：</label>
      <div class="col-sm-8">
        <select name="videotype" id="update_videotype" class="form-control">
          <option value="">请选择所属类型</option>
          {foreach $videotype as $val}
          <option value="{$val.id}">{$val.name}</option>
          {/foreach}
        </select>
        <span class="help-block m-b-none"></span>
      </div>
    </div>
    <!--视频封面-->
    <div class="form-group">
      <label class="col-sm-3 control-label">视频封面：</label>
      <div class="col-sm-8">
        <input type="button" class="btn btn-success" value="已上传的图片" id="update_selffile">
        <button type="button" class="btn btn-info" id="update_test1">上传图片</button>
        <div class="layui-upload-list">
          <img class="layui-upload-img" id="update_demo1" style='max-width:100%'>
          <p id="update_demoText"></p>
        </div>
      </div>
    </div>

    <!--上传视频-->
    <div class="form-group">
      <label class="col-sm-3 control-label">视频：</label>
      <div class="col-sm-8">
        <input type="button" class="btn btn-success" value="已上传的视频" id="update_self_video_file">
        <button type="button" class="btn btn-info" id="update_video_test1">上传视频</button>
        <div class="layui-upload-list">
          <video class="layui-upload-img" id="update_video_demo1" style='max-width:100%' controls></video>
          <p id="update_video_demoText"></p>
        </div>
      </div>
    </div>
    <!--排序-->
    <div class="form-group">
      <label class="col-sm-3 control-label">视频排序：</label>
      <div class="col-sm-8">
        <input type="number" name="sort" placeholder="视频排序" class="form-control" id="update_sort" autofocus="true">
        <span class="help-block m-b-none"></span>
      </div>
    </div>
    <!--状态-->
    <div class="form-group">
      <label class="col-sm-3 control-label">视频状态：</label>
      <div class="col-sm-8">
        <select name="status" id="update_status" class="form-control">
          <option value="1">显示</option>
          <option value="2">隐藏</option>
        </select>
        <span class="help-block m-b-none"></span>
      </div>
    </div>
  </form>
</div>
<!--  修改视频结束  -->

<!--推广二维码-->
<div id="video_qrcode">
  <img id="qrcode" src="" alt="" style="width: 70%;display:block;margin:10px auto;">
</div>

<link rel="stylesheet" href="/public/static/admin/css/imglist.css">
<!--弹出已上传的图片-->
<div class="layer_notive" >
  <ul id="imglist"></ul>
  <div style="clear:both"></div>
</div>

<script src="/public/static/admin/layui/layui.js"></script>
<!-- 全局js -->
<script src="/public/static/admin/js/jquery.min.js?v=2.1.4"></script>
<script src="/public/static/admin/js/bootstrap.min.js?v=3.3.6"></script>

<!-- 自定义js -->
<script src="/public/static/admin/js/content.js?v=1.0.0"></script>
<!-- iCheck -->
<script src="/public/static/admin/js/plugins/iCheck/icheck.min.js"></script>
<!-- Switchery -->
<script src="/public/static/admin/js/plugins/switchery/switchery.js"></script>
<script>
  $(document).ready(function () {
    // 文件有动态效果
    // $('.file-box').each(function () {
    //   animationHover(this, 'pulse');
    // });
    search("{$videtype_id}");

  });
  var $imgpath = "/public/static/admin/uploads/video_cover/";
  var $vidoepath = "/public/static/admin/uploads/video/";
  var $qrcode = "/public/static/admin/uploads/video_qrcode/";
  var photo = "";
  var video_url = "";
  var video_data = null;
  var update_photo = "";
  var update_video_url = "";

  layui.use('upload', function() { //独立版的layer无需执行这一句
    var $ = layui.jquery, layer = layui.layer,upload = layui.upload; //独立版的layer无需执行这一句
    //查询文件
    $(".search").on("click",function(){
       search($(this).data('id'));
    })
    //编辑文件
    //删除视频
    $("#filebox").on("click",".del",function(){
      var title = $(this).data("title");
      var id = $(this).data("id");
      var videotype = $(this).data("videotype");
      top.layer.msg("你确定要删除\""+title+"\"这个视频吗？",{
        time:1000*60*5,
        shade:0.8,
        btn:["确定","取消"],
        yes:function(){
          $.post("{:url('Videos/video_del')}",{id,videotype},function(data){
            top.layer.msg(data.msg,{time:2000,shade:0.8},function(){
              if(data.url){
                window.location = data.url;
              }
            })
          })
        }
      })
    })

    var active = {
      //弹出添加视频的表单
      addvideo:function(othis){
        var text = othis.data("text")
            ,type= othis.data("type");
        var actMsg = layer.open({
           type: 1
          , title: text
          , offset: [ //弹窗坐标
            ($(window).height() / 2) - 290
            , ($(window).width() / 2) - 195
          ]
          , area: ['400px', '580px']
          , id: 'layerDemo' + type //防止重复弹出
          , content: $("#file-upload-box")
          , btn: ['保存', '取消']
          , btnAlign: 'c' //按钮居中
          , shade: 0.5 //不显示遮罩
          , moveType: 1 //拖拽模式，0或者1
          , yes: function () {
            //获取表单的所有内容
            var form = $("#fileUploadForm").serializeArray();
            var data = {};
            for (item of form) {
              data[item.name] = item.value
            }
            data['video_cover'] = $imgpath+photo;
            data["url"] = $vidoepath+video_url;
            data['keywords'] = data['keywords'].replace(/，/ig,",");
            //逐个判断是否为空
            if (!data.title) { layer.msg("请输视频标题", {time: 2000, shade: 0.5}, function () { $("#title").focus(); });return ;}
            if (!data.keywords) { layer.msg("请输入关键词", {time: 2000, shade: 0.5}, function () { $("#keywords").focus();}); return ;}
            if (!data.description) { layer.msg("请输入视频描述", {time: 2000, shade: 0.5}, function () { $("#description").focus(); });return ;}
            if (!data.videotype) { layer.msg("请选择视频类型", {time: 2000, shade: 0.5}, function () { $("#videotype").focus(); }); return;}
            if (!data.video_cover) { layer.msg("请上传封面或者使用已上传的封面", {time: 2000, shade: 0.5});return ;}
            if (!data.url) { layer.msg("请上传视频或者使用已上传的视频", {time: 2000, shade: 0.5});return ;}
            if (!data.sort) { layer.msg("请输入排序", {time: 2000, shade: 0.5}, function () { $("#sort").focus(); });return ;}
            //保存专业类型
            $.post("{:url('Videos/addVideo')}", data, function (back_data) {
              layer.msg(back_data.msg, {time: 2000, shade: 0.5}, function () {
                if (back_data.url) {
                  //得到重新刷新的地址，并且后面携带tab编号（tab编号为报考类型的id，从控制器返回的结果中获得）,不能使用#号，会导致window.open() 不刷新。
                  //默认选择当前报考类型
                  window.open(back_data.url,"_self");
                }
              })
            });
          }
          , btn2: function () {
            layer.close(actMsg);
          }
        });
      },
      //天厨修改视频的表单
      update_video:function(othis){
        var text = othis.data("text")
                ,type= othis.data("type")
                ,index= othis.data("index");
       //添加数据
        $("#update_id").val(video_data[index].id);
        $("#update_title").val(video_data[index].title);
        $("#update_keywords").val(video_data[index].keywords);
        $("#update_description").val(video_data[index].description);
        $("#update_videotype option[value="+video_data[index].videotype+"]").prop("selected",true);
        $("#update_demo1").attr("src",video_data[index].video_cover);
        $("#update_video_demo1").attr("src",video_data[index].url);
        $("#update_sort").val(video_data[index].sort);
        $("#update_status option[value="+video_data[index].status+"]").prop("selected",true);

        var updateMsg = layer.open({
          type: 1
          , title: text
          , offset: [ //弹窗坐标
            ($(window).height() / 2) - 290
            , ($(window).width() / 2) - 195
          ]
          , area: ['400px', '580px']
          , id: 'layerDemo' + type //防止重复弹出
          , content: $("#update-file-upload-box")
          , btn: ['保存', '取消']
          , btnAlign: 'c' //按钮居中
          , shade: 0.5 //不显示遮罩
          , moveType: 1 //拖拽模式，0或者1
          , yes: function () {
            //获取表单的所有内容
            var form = $("#updateFileUploadForm").serializeArray();
            var data = {};
            for (item of form) {
              data[item.name] = item.value
            }
            if (update_photo){
              data['video_cover'] = $imgpath+update_photo;
            }else{
              data["video_cover"] = video_data[index].video_cover
            }
            if(update_video_url){
              data["url"] = $vidoepath+update_video_url;
            }else{
              data["url"] = video_data[index].url;
            }
            data['keywords'] = data['keywords'].replace(/，/ig,",");
            //逐个判断是否为空
            if (!data.title) { layer.msg("请输视频标题", {time: 2000, shade: 0.5}, function () { $("#update_title").focus(); });return ;}
            if (!data.keywords) { layer.msg("请输入关键词", {time: 2000, shade: 0.5}, function () { $("#update_keywords").focus();}); return ;}
            if (!data.description) { layer.msg("请输入视频描述", {time: 2000, shade: 0.5}, function () { $("#update_description").focus(); });return ;}
            if (!data.videotype) { layer.msg("请选择视频类型", {time: 2000, shade: 0.5}, function () { $("#update_videotype").focus(); }); return;}
            if (!data.video_cover) { layer.msg("请上传封面或者使用已上传的封面", {time: 2000, shade: 0.5});return ;}
            if (!data.url) { layer.msg("请上传视频或者使用已上传的视频", {time: 2000, shade: 0.5});return ;}
            if (!data.sort) { layer.msg("请输入排序", {time: 2000, shade: 0.5}, function () { $("#update_sort").focus(); });return ;}
            console.log(data);
            // 保存专业类型
            $.post("{:url('Videos/update_video')}", data, function (back_data) {
              layer.msg(back_data.msg, {time: 2000, shade: 0.5}, function () {
                if (back_data.url) {
                  //得到重新刷新的地址，并且后面携带tab编号（tab编号为报考类型的id，从控制器返回的结果中获得）,不能使用#号，会导致window.open() 不刷新。
                  //默认选择当前报考类型
                  window.open(back_data.url,"_self");
                }
              })
            });
          }
          , btn2: function () {
            layer.close(updateMsg);
          }
        });
      },
      //弹出二维码
      video_qrcode:function(othis){
        var text = othis.data("text")
                ,type= othis.data("type")
                ,qrcode= othis.data("qrcode")
        $("#qrcode").attr("src",$qrcode+qrcode);
        var qrMsg = layer.open({
          type: 1
          , title: text
          , offset: [ //弹窗坐标
            ($(window).height() / 2) - 200
            , ($(window).width() / 2) - 200
          ]
          , area: ['400px', '400px']
          , id: 'layerDemo' + type //防止重复弹出
          , content: $("#video_qrcode")
          , btn: ['保存', '取消']
          , btnAlign: 'c' //按钮居中
          , shade: 0.5 //不显示遮罩
          , moveType: 1 //拖拽模式，0或者1
          , yes: function () {
              var $a = $("<a></a>").attr("href", $qrcode+qrcode).attr("download", text);
              $a[0].click();
          }
          , btn2: function () {
            layer.close(qrMsg);
          }
        });
      },
      qrcode_refersh:function(othis){
        $.post("{:url('Videos/re_qrcode')}",{id:othis.data("id"),videotype:othis.data('videotype')},function(data){
            top.layer.msg(data.msg,{time:2000,shade:0.5},function(){
              if(data.url){
                window.location = data.url;
              }
            });

        })
      }
    }

    //普通图片上传
    var uploadInst = upload.render({
      elem: '#test1'
      ,url: "{:url('Videos/upload_cover')}"
      ,before: function(obj){
        //预读本地文件示例，不支持ie8
        obj.preview(function(index, file, result){
          $('#demo1').attr('src', result); //图片链接（base64）
        });
      }
      ,done: function(res){
        //如果上传失败
        if(res.code == 0){
          return top.layer.msg('上传失败',{shade:0.5});
        }else if(res.code){
          //上传成功
          photo = res.photo;
          return top.layer.msg('上传成功',{shade:0.5});
        }
      }
      ,error: function(){
        //演示失败状态，并实现重传
        var demoText = $('#demoText');
        demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
        demoText.find('.demo-reload').on('click', function(){
          uploadInst.upload();
        });
      }
    });
    //显示本地图片
    $("#selffile").click(function () {
      $.post("{:url('Base/getmyfiles')}",{path:$imgpath},function(data){
        console.log(data);
        var str = "";
        for( i in data.msg){
          str += "<li><img src='"+$imgpath+data.msg[i]+"' class='imglist' data-photo='"+data.msg[i]+"' onclick='changecss(this)' alt=''><div class='del_div'><i class='fa fa-close del' title='删除' data-path='"+$imgpath+data.msg[i]+"'></i></div></li>";
        }
        $("#imglist").html(str);
        //页面层
       var local_file =  layer.open({
          type: 1,
          skin: false, //加上边框
          title: "已上传的图片",
          area: ['720px', '600px'], //宽高
          btn:["确认","取消"],
          content: $(".layer_notive"),  //调到新增页面
          yes:function(){
            var newImgsrc = $(".active").attr("src");
            var newImgname = $(".active").data("photo");
            $('#demo1').attr('src', newImgsrc); //图片链接（base64）
            $('#demo1').attr('width','100%');
            photo = newImgname;
            layer.close(local_file);
          }
        });
      });
    });
    //删除图片
    $("#imglist").on("click",".del",function(v){
      $this = $(this);
      //页面层
      top.layer.msg('你确定要删除这张图片吗?', {
        time: 20000, //20s后自动关闭
        shade:0.5,
        btn: ['确定', '取消'],
        yes:function(){
          var data  = {
            "path" : $this.data("path")
          }
          $.post("{:url('Base/delfile')}",data,function(data){
            top.layer.msg(data.msg,{time:2000,shade:0.5},function(){
              $.post("{:url('Base/getmyfiles')}",{path:$imgpath},function(data) {
                console.log(data);
                var str = "";
                for (i in data.msg) {
                  str += "<li><img src='"+$imgpath + data.msg[i] + "' class='imglist' data-photo='" + data.msg[i] + "' onclick='changecss(this)' alt=''><div class='del_div'><i class='fa fa-close del' title='删除' data-path='"+$imgpath + data.msg[i] + "'></i></div></li>";
                }
                $("#imglist").html(str);
              });
            });
          });
        }
      });
    });

    //上传视频
    var video_uploadInst = upload.render({
      elem: '#video_test1'
      ,url: "{:url('Videos/upload_video')}"
      ,before: function(obj){
        //预读本地文件示例，不支持ie8
        obj.preview(function(index, file, result){
          $('#video_demo1').attr('src', result); //图片链接（base64）
        });
      }
      ,done: function(res){
        //如果上传失败
        if(res.code == 0){
          return top.layer.msg('上传失败',{shade:0.5});
        }else if(res.code){
          //上传成功
          video_url = res.video_url;
          return top.layer.msg('上传成功',{shade:0.5});
        }
      }
      ,error: function(){
        //演示失败状态，并实现重传
        var demoText = $('#demoText');
        demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
        demoText.find('.demo-reload').on('click', function(){
          video_uploadInst.upload();
        });
      }
    });
    //显示本地视频
    $("#self_video_file").click(function () {
      $.post("{:url('Base/getmyfiles')}",{path:$vidoepath},function(data){
        var str = "";
        for( i in data.msg){
          str += "<li><video src='"+$vidoepath+data.msg[i]+"' controls class='imglist' data-photo='"+data.msg[i]+"' onclick='changecss(this)' alt='' title='"+data.msg[i]+"'></video><p>"+data.msg[i]+"</p><div class='del_div'><i class='fa fa-close delvideo' title='删除' data-path='"+$vidoepath+data.msg[i]+"'></i></div></li>";
        }
        $("#imglist").html(str);
        //页面层
        var local_file =  layer.open({
          type: 1,
          skin: false, //加上边框
          title: "已上传的视频",
          area: ['720px', '600px'], //宽高
          btn:["确认","取消"],
          content: $(".layer_notive"),  //调到新增页面
          yes:function(){
            var newImgsrc = $(".active").attr("src");
            var newImgname = $(".active").data("photo");
            $('#video_demo1').attr('src', newImgsrc); //图片链接（base64）
            $('#video_demo1').attr('width','100%');
            video_url = newImgname;
            layer.close(local_file);
          }
        });
      });
    });
    //删除视频文件
    $("#imglist").on("click",".delvideo",function(v){
      $this = $(this);
      //页面层
      top.layer.msg('你确定要删除这个视频吗?', {
        time: 20000, //20s后自动关闭
        shade:0.5,
        btn: ['确定', '取消'],
        yes:function(){
          var data  = {
            "path" : $this.data("path")
          }
          $.post("{:url('Base/delfile')}",data,function(data){
            top.layer.msg(data.msg,{time:2000,shade:0.5},function(){
              $.post("{:url('Base/getmyfiles')}",{path:$vidoepath},function(data) {
                console.log(data);
                var str = "";
                for (i in data.msg) {
                  str += "<li><video src='"+$vidoepath+data.msg[i]+"' controls class='imglist' data-photo='"+data.msg[i]+"' onclick='changecss(this)' alt=''></video><div class='del_div'><i class='fa fa-close delvideo' title='删除' data-path='"+$vidoepath+data.msg[i]+"'></i></div></li>";
                }
                $("#imglist").html(str);
              });
            });
          });
        }
      });
    });

    /*--------------------------------------------------------------------------------------*/

    //修改普通图片上传
    var update_uploadInst = upload.render({
      elem: '#update_test1'
      ,url: "{:url('Videos/upload_cover')}"
      ,before: function(obj){
        //预读本地文件示例，不支持ie8
        obj.preview(function(index, file, result){
          $('#update_demo1').attr('src', result); //图片链接（base64）
        });
        load = layer.load(1,{time:1000*60*10,shade:0.5}); //搜索等待特效
      }
      ,done: function(res){
        //如果上传失败
        if(res.code == 0){
          layer.close(load);
          return top.layer.msg('上传失败',{shade:0.5});
        }else if(res.code){
          //上传成功
          update_photo = res.photo;
          layer.close(load);
          return top.layer.msg('上传成功',{shade:0.5});
        }

      }
      ,error: function(){
        //演示失败状态，并实现重传
        var demoText = $('#demoText');
        demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
        demoText.find('.demo-reload').on('click', function(){
          update_uploadInst.upload();
        });
      }
    });
    //修改显示本地图片
    $("#update_selffile").click(function () {
      $.post("{:url('Base/getmyfiles')}",{path:$imgpath},function(data){
        console.log(data);
        var str = "";
        for( i in data.msg){
          str += "<li><img src='"+$imgpath+data.msg[i]+"' class='imglist' data-photo='"+data.msg[i]+"' onclick='changecss(this)' alt=''><div class='del_div'><i class='fa fa-close del' title='删除' data-path='"+$imgpath+data.msg[i]+"'></i></div></li>";
        }
        $("#imglist").html(str);
        //页面层
        var local_file =  layer.open({
          type: 1,
          skin: false, //加上边框
          title: "已上传的图片",
          area: ['720px', '600px'], //宽高
          btn:["确认","取消"],
          content: $(".layer_notive"),  //调到新增页面
          yes:function(){
            var newImgsrc = $(".active").attr("src");
            var newImgname = $(".active").data("photo");
            $('#update_demo1').attr('src', newImgsrc); //图片链接（base64）
            $('#update_demo1').attr('width','100%');
            update_photo = newImgname;
            layer.close(local_file);
          }
        });
      });
    });

    //修改上传视频
    var update_video_uploadInst = upload.render({
      elem: '#update_video_test1'
      ,url: "{:url('Videos/upload_video')}"
      ,before: function(obj){
        //预读本地文件示例，不支持ie8
        obj.preview(function(index, file, result){
          $('#update_video_demo1').attr('src', result); //图片链接（base64）
        });
        load_2 = layer.load(1,{time:1000*60*10,shade:0.5}); //搜索等待特效
      }
      ,done: function(res){
        //如果上传失败
        if(res.code == 0){
          layer.close(load_2);
          return top.layer.msg('上传失败',{shade:0.5});
        }else if(res.code){
          //上传成功
          update_video_url = res.video_url;
          layer.close(load_2);
          return top.layer.msg('上传成功',{shade:0.5});
        }
      }
      ,error: function(){
        //演示失败状态，并实现重传
        var demoText = $('#demoText');
        demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
        demoText.find('.demo-reload').on('click', function(){
          update_video_uploadInst.upload();
        });
      }
    });
    //修改显示本地视频
    $("#update_self_video_file").click(function () {
      $.post("{:url('Base/getmyfiles')}",{path:$vidoepath},function(data){
        console.log(data);
        var str = "";
        for( i in data.msg){
          str += "<li><video src='"+$vidoepath+data.msg[i]+"' controls class='imglist' data-photo='"+data.msg[i]+"' onclick='changecss(this)' alt='' title='"+data.msg[i]+"'></video><p>"+data.msg[i]+"</p><div class='del_div'><i class='fa fa-close delvideo' title='删除' data-path='"+$vidoepath+data.msg[i]+"'></i></div></li>";
        }
        $("#imglist").html(str);
        //页面层
        var local_file =  layer.open({
          type: 1,
          skin: false, //加上边框
          title: "已上传的视频",
          area: ['720px', '600px'], //宽高
          btn:["确认","取消"],
          content: $(".layer_notive"),  //调到新增页面
          yes:function(){
            var newImgsrc = $(".active").attr("src");
            var newImgname = $(".active").data("photo");
            $('#update_video_demo1').attr('src', newImgsrc); //图片链接（base64）
            $('#update_video_demo1').attr('width','100%');
            update_video_url = newImgname;
            layer.close(local_file);
          }
        });
      });
    });



    $('.gray-bg').on('click', ".function-btn",function(){
      var othis = $(this), method = othis.data('method');
      active[method] ? active[method].call(this, othis) : '';
    });
  });

  //点击图片选择图片
  function changecss(obj){
    $(".imglist").removeClass("active");
    $(obj).addClass("active");
  }
  //查询当前分类的id
  function search(id){
    $(".search").css("color","#666");
    $("#search"+id).css("color","#23b7e5")
    var str = ""
    $.post("{:url('Videos/videolist')}",{typeid:id},function(data){
      video_data = data
       if(data.length >0) {
         var i = 0
         for (item of data) {
           var ck = item.status == 1 ? "checked" : "";
           str += "<div class=\"file-box\">" +
                   "<div class=\"file\">" +
                   "<span class=\"corner\"></span>" +
                   "<div class=\"icon\">" +
                   "<div style='width: 100%;height:100%;background-size:100% auto;background-position:center;background-image:url(" + item.video_cover + ")'></div>" +
                   "</div>" +
                   "<div class=\"file-name\">" + item.title + "<br/>" +
                   "<small>添加时间：" + item.create_time + "</small>" +
                   "<div style='line-height: 25px;'> <i title='编辑' data-type='update_video' data-text='修改视频' class=\"update fa fa-pencil function-btn\" data-method='update_video' data-index=\"" + i + "\"></i> <i title='删除' style='float: right;margin-top:7px;margin-left:5px;' data-title='" + item.title + "' data-videotype='" + item.videotype + "' class=\"del fa fa-trash-o\" data-id=\"" + item.id + "\"></i> <i title='查看二维码' class='fa fa-qrcode function-btn' data-method='video_qrcode' data-type='video_qrcode' data-qrcode='"+item.qrcode+"' data-text='扫一扫观看《"+item.title+"》视频'></i> <i class='fa fa-refresh function-btn' title='刷新二维码' data-method='qrcode_refersh' data-type='qrcode_refersh' data-videotype='"+item.videotype+"' data-id='"+item.id+"'></i><div style='display:inline-block;float:right'> <input type='checkbox' class='js-switch' data-id='" + item.id + "' title='显示与隐藏' " + ck + " /></div></div>" +
                   "</div>" +
                   "</div>" +
                   "</div>";
           i++;
         }

       }else{
         str += "<div style=\"color:#666\">暂无数据</div>";
       }
       $("#filebox").html("");
       $("#filebox").html(str);
      //状态的切换按钮的初始化样式
      var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch'));
      elems.forEach(function(html) {
        var switchery = new Switchery(html,{ size: 'small' });
      });

    })
  }
  //修改状态
  $("#filebox").on("change",".js-switch",function(){
    var checkedS = $(this).is(":checked");
    var ids = $(this).data("id");
    var st = "";
    var str = "";
    if(checkedS){
      st = 1;
      str = "显示";
    }else{
      st = 2;
      str = "隐藏";
    }
    $.post("{:url('videos/VideoStatus')}",{id:ids,status:st},function(data){
      layer.msg(str+data.msg,{time:2000});
    });
  });
</script>




</body>

</html>
